<template>
	<view>
		<view class="mainpadding">
			<view class="mainpadding">
				<view class="flexleft">
					<view class="hei_text bold wzxhx margin_top4" style=" font-size: 40rpx;">登录/注册</view>
				</view>
				<input type="password" style='width:0;height:0;min-height:0' />
				<input type="text" autocomplete="off" style='width:0;height:0;min-height:0' />
				<view class="hei_text titletext bold" style="margin-top: 140rpx;">手机号</view>
				<view class="pdl flexleft margin_top">
					<view class="xiaohui margin_right">+86</view>
					<input type="number" autocomplete="off" class="hei_text main_size bold" placeholder="请输入手机号"
						v-model="mobile">
				</view>
				<view class="hei_text titletext bold margin_top" >密码</view>
				<view class="pdl margin_top">
					<input type="password" autocomplete="off" class="hei_text main_size bold" placeholder="请输入密码"
						v-model="password">
				</view>
				<view class="flexbetween">
					<view class="xiaohuang margin_top" @click="jumpurl('/pages/login/wangjimm')">忘记密码</view>
					<view class="xiaohuang margin_top" @click="jumpurl('/pages/login/signIn')">还没账号，点击注册</view>
				</view>
				<view class="submitbtn margin_top6" @click="login()" v-if="!liandiantype">登录</view>
				<view class="submitbtn margin_top6" v-if="liandiantype">登录</view>
				
				<view class="baibtn margin_top" @click="jumpurl('/pages/login/wxlogin')">微信授权登录</view>
				<!-- <view class="margin_top5 xiaohuang flexcenter" @click="jumpurl('/pages/login/wangjimm')">本机号码一键登录</view> -->
				<view class="mainpadding posibottom">
					<view class="flexcenter margin_top" style="padding: 0 	60rpx;" @click="checkaudio">
						<view class="nocheckaudio" v-show="!type"></view>
						<view class="checkaudio" v-show="type"></view>
						<view class="xiaohui margin_left1">
							阅读并同意
							<text class="xiaohuang" @click.stop="jumpurl('/pages/system?type=1')">《用户协议》</text>
							和
							<text class="xiaohuang" @click.stop="jumpurl('/pages/system?type=2')">《隐私政策》</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				mobile: "",
				type:false,
				password:"",
				liandiantype:0
			}
		},
		methods: {
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			checkaudio(){
				this.type = !this.type
			},
			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value); 
				return a;
			},
			login(){
				let _this = this;
				if(_this.mobile == ''){
					httpRequest.toast("请输入手机号码!")
					return;
				}
				if(!_this.isMobile(_this.mobile)){
					httpRequest.toast("手机号码格式错误!")
					return;
				}
				if(this.password==""){
					httpRequest.toast("请输入密码")
					return false
				} 
				if(!this.type){
					httpRequest.toast("请认真阅读并勾选用户协议");
					return false;
				}
				this.liandiantype = 1
				uni.showLoading({
					mask:true,
					title:"请稍候"
				})
				httpRequest.request('/api/user/login','GET',{
					account:this.mobile, 
					password:this.password
				}).then(res => {
					if(res.code == 1){
						uni.hideLoading()
						httpRequest.toast('登录成功');
						uni.setStorageSync('token',res.data.userinfo.token);
						uni.setStorageSync('user_id',res.data.userinfo.user_id);
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}else{
						this.liandiantype = 0
						uni.hideLoading()
						httpRequest.toast(res.msg);
					}
				})
			},
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value); 
				return a;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.baibtn{
		width: 100%;
		border: 1rpx solid #ffa126;
		border-radius: 50rpx;
		text-align: center;
		color: #ffa126;
		padding: 20rpx 0;
	}
	
</style>